<?php
require_once("utils/Rest.inc.php");
require_once("utils/Constants.php");

class RoutingManager extends REST {
	public function handleRequest() {
		// Set strings
		$this->setLocalizedStrings();
		// Check if "manager" is set
		parse_str($_SERVER['QUERY_STRING'], $queryStringParsed);
		if (isset($queryStringParsed['manager'])) {
				$manager = $queryStringParsed['manager'];
				$file = 'managers/'.$manager.'.php';
				if (file_exists($file)) {
						require_once($file);
						$manager = new $manager();
						$manager->processApi();	
				}
		}
		// Bad request
		$jsonResults = array();
		$jsonResults[MESSAGE] = Strings::NOT_FOUND;
		$this->response($this->toJSON($jsonResults), StatusCodes::STATUS_CODE_NOT_FOUND);	
	}
	
	protected function setLocalizedStrings() {
		$headers =  apache_request_headers();
		if (isset($headers['Accept-Language'])) {
			$language = $headers['Accept-Language'];
			if ($language == "ro") {
				require_once "utils/Localized_RO.php";		
			} else {
				require_once "utils/Localized_EN.php";		
			}
		} else {
			require_once "utils/Localized_EN.php";	
		}	
	}
}
?>